﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:SQLDeploy.Builder.Converters"
             xmlns:Connections="clr-namespace:SQLDeploy.Builder.Controls.Connections" x:Class="SQLDeploy.Builder.Controls.Environments.Editor"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="450">
    <UserControl.Resources>
        <converters:ValueConverterGroup x:Key="removeEnabledConverter">
            <converters:IsObjectNullConverter/>
            <converters:BooleanReverseConverter/>
        </converters:ValueConverterGroup>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <!--BEGIN Environment Info-->
        <Grid Grid.Row="0" Margin="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <Label Grid.Column="0" Grid.Row="0" Content="Connections File:"/>
            <Grid Grid.Column="1" Grid.Row="0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBox x:Name="txt_ConnectionFile" Grid.Column="0" Grid.Row="0" Margin="4" />
                <Button Grid.Column="1" Grid.Row="0" Content="..." Margin="4" Click="Open_Click" />

            </Grid>

            <Label Grid.Column="0" Grid.Row="1" Content="Selected Environment:"/>

            <Grid Grid.Column="1" Grid.Row="1" VerticalAlignment="Top">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <ComboBox x:Name="cmb_SelectedEnvironment" Grid.Column="0" Grid.Row="0" Margin="4" 
					ItemsSource="{Binding Environments, Mode=TwoWay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
					DisplayMemberPath="Name" ClipToBounds="False" VerticalAlignment="Top"
					IsSynchronizedWithCurrentItem="True" 
                          />
                <StackPanel Grid.Column="1" Grid.Row="0" Orientation="Horizontal">

                    <Button x:Name="AddButton" Content="New..."  Margin="4,4,4,0" Height="22" Click="AddButton_Click"  />

                    <Button x:Name="RemoveButton" Content="Remove..." Margin="4,4,4,0" Height="22"
						IsEnabled="{Binding SelectedItem, Converter={StaticResource removeEnabledConverter}, ElementName=cmb_SelectedEnvironment, Mode=TwoWay}"
						Click="RemoveButton_Click"/>

                    <Button x:Name="Clone" Content="Clone.." Margin="4,4,4,0" Height="22"
						IsEnabled="{Binding SelectedItem, Converter={StaticResource removeEnabledConverter}, ElementName=cmb_SelectedEnvironment, Mode=TwoWay}"
						Click="Clone_Click"/>

                </StackPanel>

            </Grid>


        </Grid>
        <Connections:List Grid.Column="0" Grid.Row="1" MaxHeight="250" MinHeight="250"
                          DataContext="{Binding Path=Connections}"/>
        <!--END Envionrment Info-->


    </Grid>
</UserControl>
